<style>
  .inventoryProductDetailForm-title {
    width: 100%;
    margin-left: 20px;
  }

  .inventoryProductDetailForm-title .title,
  .title {
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    color: #333333;
    line-height: 19px;
    position: relative;
    padding: 6px 0 19px 0;
  }

  .inventoryProductDetailForm-title .title:after,
  .title:after {
    content: "";
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    width: calc(100% + 6px);
    height: 3px;
    background: #0a8b0a;
  }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <form class="layui-form">
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">移库记录编号：</label>
                    <div class="layui-input-inline mr0">
                      <input name="moveDownNumber" class="layui-input" type="text" placeholder="请输入移库记录编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">移出仓库：</label>
                    <div class="layui-input-inline mr0">
                      <select id="outWarehouseId2" name="outWarehouseId" lay-filter="outWarehouseId" lay-search lay-verify="">
                        <option value="">请选择移出仓库</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">移入仓库：</label>
                    <div class="layui-input-inline mr0">
                      <select id="inWarehouseId2" name="inWarehouseId" lay-filter="inWarehouseId" lay-search lay-verify="">
                        <option value="">请选择移入仓库</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">操作人：</label>
                    <div class="layui-input-inline mr0">
                      <input name="creatorName" class="layui-input" type="text" placeholder="请输入操作人名称" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">添加时间：</label>
                    <div class="layui-input-inline">
                      <input name="createTime" id="pTime" class="layui-input date-icon" type="text" placeholder="请选择创建时间" style="width: 200px" readonly />
                    </div>
                    <input name="startCreateTime" id="sTime" type="hidden" />
                    <input name="endCreateTime" id="eTime" type="hidden" />
                  </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn color-green" id="productInventorySearch" lay-filter="productInventorySearch" lay-submit>查询</button>
                    <button type="reset" class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </form>

      <div class="lay-btn-rows">
        <div class="lay-btn-box">
          <div class="lay-btn-lt">
            <button id="moveDownBtnAdd" class="layui-btn icon-btn color-reseda">添加调拨任务</button>
          </div>
          <div class="lay-btn-rt"></div>
        </div>
      </div>
      <table class="layui-table" id="movewarehouseTable" lay-filter="movewarehouseTable"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="oprateTableBar">
  <a class="layui-btn layui-btn layui-btn-xs" lay-event="detail">详情</a>
  <!-- {{# if(d.statusName!='取消'){ }} -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">取消</a>
  <!-- {{# } }} -->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="purchaseSignTaskForm">
  <form lay-filter="purchaseSignTaskForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <input name="id" type="hidden" />
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">移出仓库</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <select id="outWarehouseId" name="outWarehouseId" lay-filter="outWarehouseId" lay-search></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs3">
          <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px;">移入仓库</label>
            <div class="layui-input-block" style="margin-left: 130px;">
              <select id="inWarehouseId" name="inWarehouseId" lay-filter="inWarehouseId" lay-search></select>
            </div>
          </div>
        </div>
        <div class="layui-form-item">
          <div>
            <button id="addProduct" type="button" class="layui-btn icon-btn color-reseda">选择出库物料</button>
            <div id="productList">
              <table class="layui-table" id="moveDownWarehouseFormTable" lay-filter="moveDownWarehouseFormTable"></table>
            </div>
          </div>
        </div>
      </div>

      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" type="button" id="moveWarehouseTaskFormSubmit" lay-filter="moveWarehouseTaskFormSubmit" lay-submit>提交</button>
      </div>
    </div>
  </form>
</script>

<!--发货物料-->
<script type="text/html" id="purchaseSignTaskProductList">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料编号：</label>
                    <div class="layui-input-inline mr0">
                      <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">物料名称：</label>
                    <div class="layui-input-inline mr0">
                      <input name="productName" class="layui-input" type="text" placeholder="请输入物料名称" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <button class="layui-btn icon-btn color-green" lay-filter="deliveryRecordProductFormSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="deliveryRecordProductResets" lay-submit>重置</button>
                    <button class="layui-btn layui-btn-normal icon-btn" id="confirmChoose">确认选择</button>
                  </div>
                </div>
                <div class="query-rt"></div>
              </div>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <table class="layui-table" id="selectMoveDownProductListTable" lay-filter="selectMoveDownProductListTable"></table>
      </div>
    </div>
  </div>
</script>
<script type="text/html" id="moveDownWarehouseFormTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "laydate"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laydate = layui.laydate;
    var unitName;

    //仓库列表
    admin.initDataSelect("enterprisecab/warehouse/admin/warehouse/list", { limit: 9999 }, "outWarehouseId2", null, "仓库", null, null);
    admin.initDataSelect("enterprisecab/warehouse/admin/warehouse/list", { limit: 9999 }, "inWarehouseId2", null, "仓库", null, null);

    laydate.render({
      elem: "#pTime",
      type: "date",
      range: true,
      done: function (value, date, endDate) {
        if (value) {
          var dateValue = value.split(" - ");
          $("#sTime").val(dateValue[0] + " 00:00:00");
          $("#eTime").val(dateValue[1] + " 23:59:59");
        } else {
          $("#sTime").val();
          $("#eTime").val();
        }
      }
    });

    //仓库列表
    /*   admin.initDataSelect("enterprisecab/warehouse/admin/warehouse/list", {limit: 9999}, "inWarehouseId", null, "仓库", null, null);
     */

    // 渲染表格
    var insTb = table.render({
      elem: "#movewarehouseTable",
      url: config.base + "enterprisecab/warehouse/admin/moveDownWareHouse/list",
      page: true,
      limit: 10,
      limits: [5, 10, 20, 30, 40, 50, 60, 70, 80],
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号", width: 60 },
          { field: "moveDownNumber", align: "center", title: "移库记录编号" },
          { field: "skuNum", align: "center", title: "移库物料数" },
          { field: "outWarehouseName", align: "center", title: "移出仓库" },
          // , {field: 'areaNum', align: 'center', title: '涉及库位'}
          { field: "inWarehouseName", align: "center", title: "移入仓库" },
          { field: "statusName", align: "center", title: "状态" },
          { field: "creatorName", align: "center", title: "操作人" },
          { field: "createTime", align: "center", title: "添加时间" },
          { align: "center", toolbar: "#oprateTableBar", title: "操作", width: 200 }
        ]
      ],
      done: function (res, curr, count) {}
    });
    form.render("select");

    // 工具条点击事件
    table.on("tool(movewarehouseTable)", function (obj) {
      var data = obj.data;

      if (obj.event == "detail") {
        showEditModel(data);
      } else if (obj.event == "cancel") {
        // 是否确认
        layer.confirm("是否确认取消移库任务", { icon: 3, title: "提示" }, function (index) {
          layer.close(index);
          admin.req("enterprisecab/warehouse/admin/moveDownWareHouse/cancel/" + data.id, {}, function (res) {
            if (res.code == 200) {
              layer.msg("取消成功");
              table.reload("movewarehouseTable");
            }
          });
        });
      }
    });

    // 搜索
    form.on("submit(productInventorySearch)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
      return false;
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".lay-query-box").find("select").val("");
      $(".lay-query-box").find("input").val("");
      xmSelect.get("#selectProductType")[0].setValue([]);
      var field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
    });

    // 添加按钮点击事件
    $("#moveDownBtnAdd").click(function () {
      showEditModel();
    });

    // 显示编辑弹窗2
    function showEditModel(data) {
      admin.open({
        type: 1,
        area: ["80%", "90%"],
        offset: ["8%", "15%"],
        title: "添加调拨任务",
        content: $("#purchaseSignTaskForm").html(),
        success: function () {
          //仓库列表
          admin.initDataSelect("enterprisecab/warehouse/admin/warehouse/list", { limit: 9999 }, "outWarehouseId", data ? data.outWarehouseId : null, "仓库", null, null);
          admin.initDataSelect("enterprisecab/warehouse/admin/warehouse/list", { limit: 9999 }, "inWarehouseId", data ? data.inWarehouseId : null, "仓库", null, null);
          table.render({
            elem: "#moveDownWarehouseFormTable",
            data: [],
            page: false,
            cellMinWidth: 100,
            cols: [
              [
                { type: "numbers", align: "center", height: 70, title: "序号" },
                { field: "skuId", align: "center", title: "skuId", width: 160, hide: true },
                { field: "skuCode", align: "center", title: "物料编号", width: 160 },
                { field: "skuName", align: "center", title: "物料名称", width: 160 },
                { field: "skuSpec", align: "center", title: "物料规格", width: 160 },
                { field: "warehouseName", align: "center", title: "所在仓库", hide: data, width: 160 },
                // {field: 'warehouseAreaName', align: 'center', title: '所在库区'},
                // {field: 'shelfSpaceCode', align: 'center', title: '库位编码'},
                // {field: 'palletBoxCode', align: 'center', title: '料箱号'},
                { field: "warehouseId", align: "center", title: "原仓库id", hide: true },
                // {field: 'warehouseAreaId', align: 'center', title: '原库区id',hide: true},
                // {field: 'shelfSpaceId', align: 'center', title: '原库位ID',hide: true},
                { field: "firstNum", align: "center", title: "在库数量", width: 160 },
                {
                  field: "moveNum",
                  align: "center",
                  title: "移库数量",
                  width: 160,
                  hide: data,
                  templet: function (d) {
                    return admin.setTableInput("moveNum", data, "moveNum")(d);
                  }
                },
                // {
                //     field: "outWarehouseAreaId",
                //     align: "center",
                //     title: "出库库区",
                //     width: 170,
                //     templet: (d) => {
                //         /* if (d.warehouseShelfSpaceIdList) {
                //              let options = d.warehouseShelfSpaceIdList;
                //              return admin.setTableSelect("warehouseShelfSpaceId", options, false, "warehouseShelfSpaceId")(d);
                //          } else {
                //              return "";
                //          }*/
                //         return admin.setTableSelect("outWarehouseAreaId", [], false, "outWarehouseAreaId")(d);
                //     }
                // },
                // {
                //     field: "outWarehouseShelfSpaceId",
                //     align: "center",
                //     title: "出库库位",
                //     width: 170,
                //     templet: (d) => {
                //        /* if (d.warehouseShelfSpaceIdList) {
                //             let options = d.warehouseShelfSpaceIdList;
                //             return admin.setTableSelect("warehouseShelfSpaceId", options, false, "warehouseShelfSpaceId")(d);
                //         } else {
                //             return "";
                //         }*/
                //         return admin.setTableSelect("outWarehouseShelfSpaceId", [], false, "outWarehouseShelfSpaceId")(d);
                //     }
                // },
                // {
                //     field: "outPalletBoxId",
                //     align: "center",
                //     title: "出库料箱",
                //     width: 170,
                //     templet: function (d) {
                //         return admin.setTableSelect("outPalletBoxId", [], false, "outPalletBoxId")(d);
                //     },
                // },
                // {
                //     field: "inWarehouseAreaId",
                //     align: "center",
                //     title: "入库库区",
                //     width: 170,
                //     templet: (d) => {
                //         /* if (d.warehouseShelfSpaceIdList) {
                //              let options = d.warehouseShelfSpaceIdList;
                //              return admin.setTableSelect("warehouseShelfSpaceId", options, false, "warehouseShelfSpaceId")(d);
                //          } else {
                //              return "";
                //          }*/
                //         return admin.setTableSelect("inWarehouseAreaId", [], false, "inWarehouseAreaId")(d);
                //     }
                // },
                // {
                //     field: "inWarehouseShelfSpaceId",
                //     align: "center",
                //     title: "入库库位",
                //     width: 170,
                //     templet: function (d) {
                //         return admin.setTableSelect("inWarehouseShelfSpaceId", [], false, "inWarehouseShelfSpaceId")(d);
                //     },
                // },
                // {
                //     field: "inPalletBoxId",
                //     align: "center",
                //     title: "入库料箱",
                //     width: 170,
                //     templet: function (d) {
                //         return admin.setTableSelect("inPalletBoxId", [], false, "inPalletBoxId")(d);
                //     },
                // },
                {
                  field: "remark",
                  align: "center",
                  title: "备注",
                  width: 200,
                  templet: function (d) {
                    return admin.setTableInput("remark", data, "remark")(d);
                  }
                },
                {
                  align: "center",
                  toolbar: "#moveDownWarehouseFormTableBar",
                  title: "操作",
                  width: 100,
                  fixed: "right",
                  hide: data
                }
              ]
            ],
            done: function () {
              admin.tableInputChange("moveDownWarehouseFormTable");
            }
            /*done: function (res, curr, count) {
                            // 获取所有行数据
                            let that = this;
                            let tableId = $(that.elem).attr('id');

                            let outWarehouseId=$("#outWarehouseId").val();
                            //todo 1  获取移出仓库 对应的库位信息                        获取对应料箱信息    把对应的料箱信息根据库位信息过滤出来
                            admin.req('enterprisecab/warehouse/admin/moveDownWareHouse/getNowKuWeiInfo', {inWarehouseId: outWarehouseId}, function (res) {
                                if (res.code === 200) {
                                    // debugger;
                                    // var options = res.data || [];

                                    // 遍历每行，设置“出库库位”下拉框内容
                                    $('#' + tableId + ' .layui-table-body tbody tr').each(function (index, trElem) {
                                        var $tr = $(trElem);
                                        var d = res.data[index]; // 当前行数据

                                        // 获取出库库位下拉框
                                        var $spaceSelect = $tr.find('select[name="outWarehouseShelfSpaceId"]');

                                        // 清空旧内容
                                        $spaceSelect.empty();

                                        // 填充选项
                                        admin.fillSelect($spaceSelect, options);

                                        // ✅ 关键：设置默认选中值
                                        var val = d.outWarehouseShelfSpaceId;
                                        if (val !== null && val !== undefined && val !== '') {
                                            $spaceSelect.val(val);
                                        }
                                        // 渲染 select 控件
                                        layui.form.render('select');
                                    });


                                    // 绑定 change 事件
                                    $('#' + tableId + ' .layui-table-body tbody').off('change', 'select[name="outWarehouseShelfSpaceId"]').on('change', 'select[name="outWarehouseShelfSpaceId"]', function () {
                                        var $row = $(this).closest('tr');
                                        var warehouseShelfSpaceId = $(this).val();

                                        // 获取对应行的 outPalletBoxId 下拉框
                                        var $palletBoxSelect = $row.find('select[name="outPalletBoxId"]');

                                        if (!warehouseShelfSpaceId) {
                                            // 如果未选库位，清空料箱下拉框
                                            admin.fillSelect($palletBoxSelect, []);
                                            layui.form.render('select');
                                            return;
                                        }

                                        admin.req('enterprisecab/warehouse/admin/moveDownWareHouse/getNowLiaoXiangInfo', {
                                            outWarehouseId: outWarehouseId,
                                            warehouseShelfSpaceId: warehouseShelfSpaceId
                                        }, function (res) {
                                            if (res.code === 200) {
                                                var boxOptions = res.data || [];
                                                admin.fillSelect($palletBoxSelect, boxOptions);
                                                layui.form.render('select');
                                            } else {
                                                admin.fillSelect($palletBoxSelect, []);
                                                layui.form.render('select');
                                                layer.msg('获取料箱失败');
                                            }
                                        });
                                    });
                                }
                           });
                        },*/
          });

          admin.fillSelect = function ($select, list) {
            $select.empty();
            if (list.length === 0) {
              $select.append('<option value="">无数据</option>');
              return;
            }
            for (var i = 0; i < list.length; i++) {
              var item = list[i];
              $select.append('<option value="' + item.id + '">' + item.name + "</option>");
            }
          };
          if (data) {
            $("#addProduct").hide();
            $("#moveWarehouseTaskFormSubmit").hide();
            admin.req("enterprisecab/warehouse/admin/moveDownWareHouse/detail/" + data.id, {}, function (res) {
              if (res.code == 200) {
                table.reload("moveDownWarehouseFormTable", {
                  data: res.data.moveDownWarehouseItermVOList
                });
              }
            });
          }
          table.on("tool(moveDownWarehouseFormTable)", function (obj) {
            var d = obj.data; // 获取当前行的数据
            var layEvent = obj.event; // 获取事件名（edit 或 del）
            if (obj.tr) {
              obj.tr.on("click", function (e) {
                e.preventDefault(); // 防止默认行为
              });
            }
            if (layEvent == "del") {
              const index = $(obj.tr[0]).data("index");
              let list = table.cache["moveDownWarehouseFormTable"].filter((v) => {
                return v["LAY_TABLE_INDEX"] != index;
              });
              table.reload("moveDownWarehouseFormTable", {
                data: list
              });
            }
          });

          var codeArr = [];
          var deliveryRecordProductList = [];

          // 添加发货物料
          $("#addProduct").click(function () {
            let outWarehouseId = $("#outWarehouseId").val();
            let inWarehouseId = $("#inWarehouseId").val();
            if (outWarehouseId == null || outWarehouseId == undefined || outWarehouseId == "") {
              return layer.msg("请选择移出仓库");
            }
            if (inWarehouseId == null || inWarehouseId == undefined || inWarehouseId == "") {
              return layer.msg("请选择移入仓库");
            }
            var purchaseSignTaskProductList = admin.open({
              type: 1,
              area: ["80%", "85%"],
              offset: ["10%", "17%"],
              title: "物料列表",

              content: $("#purchaseSignTaskProductList").html(),
              success: function () {
                // 渲染表格
                var insTb = table.render({
                  elem: "#selectMoveDownProductListTable",
                  url: config.base + "enterprisecab/warehouse/admin/moveDownWareHouse/getGoodsList",
                  where: { outWarehouseId: outWarehouseId },
                  page: true,
                  cellMinWidth: 100,
                  cols: [
                    [
                      { type: "checkbox" },
                      { field: "id", align: "center", title: "ID", hide: "true" },
                      // {field: 'skuId', align: 'center', title: 'skuId', width: 160},
                      { field: "skuCode", align: "center", title: "物料编号", width: 160 },
                      { field: "skuName", align: "center", title: "物料名称", width: 160 },
                      { field: "skuSpec", align: "center", title: "物料规格", width: 160 },
                      { field: "firstNum", align: "center", title: "在库数量" },
                      { field: "warehouseName", align: "center", title: "所在仓库", width: 100 },
                      // { field: "warehouseAreaName", align: "center", title: "所在库区" },
                      // { field: "shelfSpaceCode", align: "center", title: "库位编码" },
                      // { field: "warehouseId", align: "center", title: "仓库id", hide: true },
                      // { field: "warehouseAreaId", align: "center", title: "库区id", hide: true },
                      // { field: "shelfSpaceId", align: "center", title: "库位ID", hide: true }
                    ]
                  ]
                });
                // 搜索
                form.on("submit(deliveryRecordProductFormSubSearchLog)", function (data) {
                  insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
                });
                // 重置搜索
                form.on("submit(deliveryRecordProductResets)", function (data) {
                  $(".lay-header").find("select").val("");
                  $(".lay-header").find("input").val("");
                  let field = data.field;
                  for (let key in field) {
                    field[key] = "";
                  }
                  insTb.reload({ where: field, page: { curr: 1 } }, "data");
                });
                // 确认选择
                $("#confirmChoose").click(function () {
                  var checkStatus = table.checkStatus("selectMoveDownProductListTable"); //test即为基础参数id对应的值
                  var dataS = checkStatus.data;
                  if (dataS.length == 0) {
                    layer.msg("请选择物料", { icon: 2, time: 1000 });
                  } else {
                    for (var i = 0; i < dataS.length; i++) {
                      dataS[i].purchaseOrderDetailId = dataS[i].id;
                      deliveryRecordProductList.push(dataS[i]);
                      codeArr.push(dataS[i].skuCode);
                    }
                    layer.close(purchaseSignTaskProductList);
                    // 获取数据集合并传入表格中
                    table.reload("moveDownWarehouseFormTable", {
                      data: deliveryRecordProductList,
                      limit: deliveryRecordProductList.length
                    });
                  }
                });
              }
            });
          });

          // 表单提交事件
          form.on("submit(moveWarehouseTaskFormSubmit)", function (d) {
            // var moveWarehouseRecordProducts = [];
            // $("#productList")
            //   .find("tbody tr")
            //   .each(function (index, item) {
            //     var moveWarehouseRecordProduct = {};
            //     $(item)
            //       .find("td")
            //       .each(function (tdIndex, tdItem) {
            //         if ($(tdItem).data("field") == "skuCode") {
            //           moveWarehouseRecordProduct.skuCode = $(tdItem).find("div").text();
            //         }
            //         if ($(tdItem).data("field") == "skuName") {
            //           moveWarehouseRecordProduct.skuName = $(tdItem).find("div").val();
            //         }
            //         if ($(tdItem).data("field") == "skuSpec") {
            //           moveWarehouseRecordProduct.skuSpec = $(tdItem).find("div").val();
            //         }
            //         if ($(tdItem).data("field") == "firstNum") {
            //           moveWarehouseRecordProduct.firstNum = $(tdItem).find("div").val();
            //         }
            //         if ($(tdItem).data("field") == "moveNum") {
            //           moveWarehouseRecordProduct.moveNum = $(tdItem).find("input").val();
            //         }
            //       });
            //     if (!$.isEmptyObject(moveWarehouseRecordProduct)) {
            //       moveWarehouseRecordProducts.push(moveWarehouseRecordProduct);
            //     }
            //   });
            let moveWarehouseRecordProducts = table.cache["moveDownWarehouseFormTable"];
            if ($("#outWarehouseId").val() == $("#inWarehouseId").val()) {
              return layer.msg("移出仓库和移入仓库不能相同", { icon: 2 });
            }
            if (moveWarehouseRecordProducts.length < 0) {
              return layer.msg("至少添加一条物料信息！", { icon: 2 });
            }
            let noNumObj = moveWarehouseRecordProducts.find((v) => {
              return !v.moveNum || v.moveNum - v.firstNum > 0
            });
            console.log(noNumObj);
            if (noNumObj) {
              return layer.msg(noNumObj.skuCode + "的移库数量未填写或者大于在库数量", { icon: 2 });
            }

            // if (moveWarehouseRecordProducts.length > 0) {
            //   for (var i = 0; i < moveWarehouseRecordProducts.length; i++) {
            //     let moveNum = moveWarehouseRecordProducts[i].moveNum;
            //     if (!/^\d+(\.\d+)?$/.test(moveNum) || Number(moveNum) <= 0) {
            //       return layer.msg("移库数量必须为大于0的数字", { icon: 2 });
            //     }
            //     moveWarehouseRecordProducts[i].moveNum = Number(moveNum);
            //     if (moveWarehouseRecordProducts[i].firstNum < moveWarehouseRecordProducts[i].moveNum) {
            //       return layer.msg("移库数量超出在库数量", { icon: 2 });
            //     }
            //   }
            layer.load(2);
            d.field.moveDownWarehouseItermFormList = moveWarehouseRecordProducts;
            admin.req(
              data ? "enterprise/warehouse/admin/moveDownWareHouse/update" : "enterprisecab/warehouse/admin/moveDownWareHouse/add",
              JSON.stringify(d.field),
              function (res) {
                layer.closeAll("loading");
                if (res.code == 200) {
                  layer.msg(res.msg, { icon: 1 });
                  table.reload("purchaseSignTaskTable");
                  layer.closeAll("page");
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
              data ? "PUT" : "POST",
              false,
              "application/json"
            );
            // } else {
            //   layer.msg("至少添加一条发货物料！", { icon: 2 });
            // }
            return false;
          });
        }
      });
    }
  });
</script>
